﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Util.Classes
{
    /// <summary>
    /// Represents defusable bomb
    /// </summary>
    public class Bomb
    {
        #region properties
        public string Name;
        public string Texture ;
        public string TextureInactive;
        public double Width;
        public double Height;
        public Util.Helpers.PublicEnums.ExplosionType ExplosionType;
        public int BonusTime; //how much time is added when player defuses the bomb
        public List<Event> Events;
        public BombWireShuffle Shuffle;//holds info how to behave when shuffle occurs
        public List<BombWire> Wires; //colors and textures of bomb's wires
        public int Difficulty; //0-easy, 1-medium, 2-hard
        public double DefusingWireGracePeriod;//how long after first (defusing) wire is shown, the rest of the wires are shown
        //public bool IsDefused { get; set; } //if true, the bomb defused
        public double TimeToSubtractOnBombFailed; //how much time subtract when user fails to defuse the bomb

        
        
        #endregion

        #region public fields
        //helpers
        public string ExplosionTypeString;
        public List<BombWireShuffle> ShuffleHelperList; //linq must get items to the list; it will be later on converted into 1 class
        public int PositionsSetCT; //list that is used to know how many wires have already a position set
        #endregion


        #region public methods and functions

        /// <summary>
        /// Default constructor
        /// </summary>
        public Bomb()
        {
            try
            {
                Events = new List<Event>();
                PositionsSetCT = 0;

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Parse explosion type from
        /// string to enum
        /// </summary>
        public void DoConversions()
        {
            try
            {
                switch (ExplosionTypeString)
                {
                    case "Small":
                        {
                            this.ExplosionType = Util.Helpers.PublicEnums.ExplosionType.small;
                            break;
                        }
                    case "Medium":
                        {
                            this.ExplosionType = Util.Helpers.PublicEnums.ExplosionType.medium;
                            break;
                        }
                    case "Large":
                        {
                            this.ExplosionType = Util.Helpers.PublicEnums.ExplosionType.large;
                            break;
                        }

                }

                //cleanup
                ExplosionTypeString = null;

                //convert shuffle list to 1 class
                if (this.ShuffleHelperList != null)
                {
                    this.Shuffle = new BombWireShuffle();
                    this.Shuffle.ShufflePeriod = this.ShuffleHelperList[0].ShufflePeriod;
                    this.Shuffle.ShuffleSpeed = this.ShuffleHelperList[0].ShuffleSpeed;
                    this.Shuffle.Turns = this.ShuffleHelperList[0].Turns;

                    //cleanup
                    this.ShuffleHelperList = null;
                }


                //PARSE EVENTS
                for (int i = 0; i < this.Events.Count; i++)
                {
                    //Event
                    #region event type

                    switch (this.Events[i].EventTypeString)
                    {
                        case "onDefuseStart":
                            {
                                this.Events[i].EventType = Util.Helpers.PublicEnums.EventType.onDefuseStart;
                                this.Events[i].EventTypeString = null;
                                break;
                            }
                        case "onBombDefused":
                            {
                                this.Events[i].EventType = Util.Helpers.PublicEnums.EventType.onBombDefused;
                                this.Events[i].EventTypeString = null;
                                break;
                            }
                        case "onDefuseFailed":
                            {
                                this.Events[i].EventType = Util.Helpers.PublicEnums.EventType.onDefuseFailed;
                                this.Events[i].EventTypeString = null;
                                break;
                            }
                    }

                    #endregion
                }


                //Shuffle move types
                if (Shuffle.Turns != null)
                {
                    for (int i = 0; i < Shuffle.Turns.Count; i++)
                    {
                       //loop throug turns

                        if (Shuffle.Turns[i].Moves != null)
                        {
                            //loop throug moves

                            for (int i1 = 0; i1 < Shuffle.Turns[i].Moves.Count; i1++)
                            {
                                //convert strings into types
                                switch (Shuffle.Turns[i].Moves[i1].MoveTypeString)
                                {
                                    case "1-2":
                                        {

                                            Shuffle.Turns[i].Moves[i1].MoveType=Helpers.PublicEnums.WireShuffleType.oneTwo;

                                            break;
                                        }
                                    case "2-3":
                                        {

                                            Shuffle.Turns[i].Moves[i1].MoveType=Helpers.PublicEnums.WireShuffleType.TwoThree;
                                            break;

                                        }
                                    case "4-5":
                                        {
                                            Shuffle.Turns[i].Moves[i1].MoveType=Helpers.PublicEnums.WireShuffleType.FourFive;
                                            break;

                                        }
                                    case "5-6":
                                        {
                                            Shuffle.Turns[i].Moves[i1].MoveType=Helpers.PublicEnums.WireShuffleType.FiveSix;
                                            break;
                                        }
                                    case "1-1":
                                        {
                                            Shuffle.Turns[i].Moves[i1].MoveType = Helpers.PublicEnums.WireShuffleType.oneOne;
                                            break;
                                        }
                                    case "2-2":
                                        {
                                            Shuffle.Turns[i].Moves[i1].MoveType = Helpers.PublicEnums.WireShuffleType.twoTwo;
                                            break;
                                        }
                                    case "3-3":
                                        {
                                            Shuffle.Turns[i].Moves[i1].MoveType = Helpers.PublicEnums.WireShuffleType.threeThree;
                                            break;
                                        }
                                    case "6-7":
                                        {
                                            Shuffle.Turns[i].Moves[i1].MoveType = Helpers.PublicEnums.WireShuffleType.sixSeven;
                                            break;
                                        }
                                    case "7-8":
                                        {
                                            Shuffle.Turns[i].Moves[i1].MoveType = Helpers.PublicEnums.WireShuffleType.sevenEight;
                                            break;
                                        }


                                }


                                //cleanup
                                Shuffle.Turns[i].Moves[i1].MoveTypeString = null;
                            }
                        }
                    }
                }


           


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }




        #endregion


    }
}
